"""add avatar and cover to user

Revision ID: 7c6641d4f934
Revises: 58ae85582ba0
Create Date: 2021-01-19 12:31:13.031546

"""
# revision identifiers, used by Alembic.
from alembic import op
from depot.fields.sqlalchemy import UploadedFileField
import sqlalchemy as sa
from sqlalchemy import types

revision = "7c6641d4f934"
down_revision = "c459890b7103"

REDUCED_SIZE_FOR_DEPOT_STORAGE_FIELDS = 3000


# HACK - G.M -  2021-03-11 - reconvert to reduced size varchar instead of 4000
# to be compliant with mysql/mariadb on utf8bm4
class ReducedSizeUploadFileField(UploadedFileField):
    def load_dialect_impl(self, dialect):
        return dialect.type_descriptor(types.VARCHAR(3000))


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("users") as batch_op:
        batch_op.add_column(sa.Column("avatar", ReducedSizeUploadFileField(), nullable=True))
        batch_op.add_column(sa.Column("cover", ReducedSizeUploadFileField(), nullable=True))
        batch_op.add_column(
            sa.Column("cropped_avatar", ReducedSizeUploadFileField(), nullable=True)
        )
        batch_op.add_column(sa.Column("cropped_cover", ReducedSizeUploadFileField(), nullable=True))
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("users") as batch_op:
        batch_op.drop_column("cropped_cover")
        batch_op.drop_column("cropped_avatar")
        batch_op.drop_column("cover")
        batch_op.drop_column("avatar")
    # ### end Alembic commands ###
